package com.xigua.chapter_5_Singleton.example;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2022/3/3021:16
 */
public class Singleton {

    private static volatile Singleton singleton = null ;

    private Singleton() {
        System.out.println("只生成一个实例");
    }

    public static Singleton getSingleton() {
        if (singleton == null ){
            synchronized (Singleton.class){
                if (singleton == null){
                    singleton = new Singleton();
                }
            }
        }
        return singleton;
    }
}
